<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
        function a_game(pNum,out){
var monkey_num=[];
for(var i=1;i<pNum;i++){
monkey_num.push(i);
}
var step=0;
if(out==1){
return monkey_num[monkey_num.length-1];
}else{
    while(monkey_num.length>1){
        var outnum=0;
        var len=monkey_num.length;
        for(var i=0;i<len;i++){
            step++;
            if(step==out){
                step=0;
                console.log("出局："+monkey_num[i-outnum]);
                monkey_num.splice(i-outnum,1);
                outnum++;
            }
        }
    }
    return monkey_num[0];
}
}
console.log("大王是："+a_game(3,2));
    </script>
</body>
</html>